//
//  ST_TrophyChildViewController.swift
//  btvideo
//
//  Created by mac on 2021/7/7.
//  Copyright © 2021 JarvanZhang. All rights reserved.
//

import UIKit
import JXSegmentedView

class ST_TrophyChildViewController: UIViewController {
    var titles = [String]()
    let segmented_data_source = JXSegmentedTitleDataSource()
    let segmentedView = JXSegmentedView()
    lazy var listContainerView: JXSegmentedListContainerView! = {
        return JXSegmentedListContainerView(dataSource: self)
    }()
    
    var parentType:ST_TrophyRankType?

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .clear
        
       
        
        view.addSubview(segmentedView)
        segmentedView.snp.makeConstraints { (make) in
            make.height.equalTo(34)
            make.top.centerX.equalToSuperview().offset(5)
            make.left.equalToSuperview().offset(17)
            make.right.equalToSuperview().offset(-17)
        }
        segmentedView.cornerRadius = 34/2.0
        segmentedView.borderColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 0.6)
        segmentedView.borderWidth = 1
        
        //配置数据源
        segmented_data_source.itemSpacing = 2
        segmented_data_source.itemWidth = 113
        segmented_data_source.isTitleColorGradientEnabled = true
        segmented_data_source.titles = titles
        segmented_data_source.titleNormalFont = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.regular)
        segmented_data_source.titleNormalFont = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.medium)
        segmented_data_source.titleNormalColor = UIColor.white
        segmented_data_source.titleSelectedColor = UIColor.white
        
        //配置指示器
        let indicator = JXSegmentedIndicatorBackgroundView()
        indicator.indicatorHeight = 30
        indicator.indicatorWidth = 113
        indicator.indicatorColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 0.2)
        segmentedView.indicators = [indicator]
        
        segmentedView.dataSource = segmented_data_source
        segmentedView.backgroundColor = .clear
        segmentedView.contentEdgeInsetLeft = 0
        segmentedView.contentEdgeInsetRight = 0

        segmentedView.listContainer = listContainerView
        view.addSubview(listContainerView)
        listContainerView.snp.makeConstraints { (make) in
            make.top.equalTo(segmentedView.snp.bottom)
            make.left.bottom.right.equalToSuperview()
        }
    }
}

extension ST_TrophyChildViewController: JXSegmentedListContainerViewListDelegate {
    func listView() -> UIView {
        return view
    }
}

extension ST_TrophyChildViewController: JXSegmentedListContainerViewDataSource {
    func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
        if let titleDataSource = segmentedView.dataSource as? JXSegmentedBaseDataSource {
            return titleDataSource.dataSource.count
        }
        return 0
    }

    func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
        
        
        let vc = ST_TrophyChildDetailViewController()
        
        if let type = parentType,let tail = ST_TrophyRankTimeintervalStyle.allCases[safe: index]{
            vc.rankType = type
            vc.timeinterval_type = tail
        }
        
        
        return vc
    }
}
